load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "stats",
    srcs = [
        "automatic_stats.go",
        "delete_stats.go",
        "forecast.go",
        "histogram.go",
        "json.go",
        "merge.go",
        "most_common_values.go",
        "new_stat.go",
        "quantile.go",
        "row_sampling.go",
        "simple_linear_regression.go",
        "stats_cache.go",
        "util.go",
    ],
    embed = [":stats_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/stats",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base",
        "//pkg/clusterversion",
        "//pkg/jobs/jobspb",
        "//pkg/keys",
        "//pkg/kv/kvclient/rangefeed",
        "//pkg/kv/kvpb",
        "//pkg/roachpb",
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/catenumpb",
        "//pkg/sql/catalog/catpb",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/descs",
        "//pkg/sql/isql",
        "//pkg/sql/memsize",
        "//pkg/sql/opt/cat",
        "//pkg/sql/parser",
        "//pkg/sql/rowenc",
        "//pkg/sql/rowenc/keyside",
        "//pkg/sql/rowenc/valueside",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sessiondata",
        "//pkg/sql/sqlerrors",
        "//pkg/sql/types",
        "//pkg/util/cache",
        "//pkg/util/container/heap",
        "//pkg/util/encoding",
        "//pkg/util/errorutil",
        "//pkg/util/hlc",
        "//pkg/util/intsets",
        "//pkg/util/log",
        "//pkg/util/mon",
        "//pkg/util/protoutil",
        "//pkg/util/sentryutil",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/timeutil/pgdate",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
    ],
)

go_test(
    name = "stats_test",
    size = "medium",
    srcs = [
        "automatic_stats_manual_test.go",
        "automatic_stats_test.go",
        "create_stats_job_test.go",
        "delete_stats_test.go",
        "forecast_test.go",
        "histogram_test.go",
        "main_test.go",
        "merge_test.go",
        "quantile_test.go",
        "row_sampling_test.go",
        "simple_linear_regression_test.go",
        "stats_cache_test.go",
        "stats_test.go",
    ],
    embed = [":stats"],
    exec_properties = select({
        "//build/toolchains:is_heavy": {"test.Pool": "large"},
        "//conditions:default": {"test.Pool": "default"},
    }),
    shard_count = 8,
    deps = [
        "//pkg/base",
        "//pkg/jobs",
        "//pkg/jobs/jobspb",
        "//pkg/keys",
        "//pkg/kv",
        "//pkg/kv/kvclient/rangefeed",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver",
        "//pkg/kv/kvserver/kvserverbase",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/server",
        "//pkg/settings/cluster",
        "//pkg/sql",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/bootstrap",
        "//pkg/sql/catalog/catpb",
        "//pkg/sql/catalog/colinfo",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/descs",
        "//pkg/sql/catalog/desctestutils",
        "//pkg/sql/catalog/tabledesc",
        "//pkg/sql/execinfra",
        "//pkg/sql/isql",
        "//pkg/sql/opt/cat",
        "//pkg/sql/randgen",
        "//pkg/sql/rowenc",
        "//pkg/sql/rowenc/valueside",
        "//pkg/sql/rowexec",
        "//pkg/sql/sem/catid",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/tree",
        "//pkg/sql/types",
        "//pkg/testutils",
        "//pkg/testutils/jobutils",
        "//pkg/testutils/serverutils",
        "//pkg/testutils/skip",
        "//pkg/testutils/sqlutils",
        "//pkg/testutils/testcluster",
        "//pkg/util/encoding",
        "//pkg/util/intsets",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/mon",
        "//pkg/util/protoutil",
        "//pkg/util/randutil",
        "//pkg/util/retry",
        "//pkg/util/timeutil",
        "//pkg/util/timeutil/pgdate",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_lib_pq//oid",
        "@com_github_stretchr_testify//require",
    ],
)

proto_library(
    name = "stats_proto",
    srcs = [
        "histogram.proto",
        "table_statistic.proto",
    ],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/sql/types:types_proto",
        "@com_github_gogo_protobuf//gogoproto:gogo_proto",
        "@com_google_protobuf//:timestamp_proto",
    ],
)

go_proto_library(
    name = "stats_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/stats",
    proto = ":stats_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/sql/types",
        "@com_github_gogo_protobuf//gogoproto",
    ],
)
